//
//  CoreTableViewController.m
//  LearnDemo
//
//  Created by 龙 on 2018/5/21.
//  Copyright © 2018年 longlong. All rights reserved.
//

#define CellIdentifer @"UITableViewCell"

#import "CoreTableViewController.h"

@interface CoreTableViewController ()
@property (nonatomic ,strong) NSArray<NSString *> *titleArray;
@property (nonatomic ,strong) NSArray<NSString *> *controllerArray;
@end

@implementation CoreTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifer];
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArray.count;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    cell.layer.transform = CATransform3DMakeScale(0.1, 0.1, 1);
    //x和y的最终值为1
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifer forIndexPath:indexPath];
    cell.textLabel.text = self.titleArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *className = self.controllerArray[indexPath.row];
    [self pushToTheController:className];
}

#pragma mark - Private Methods

- (void)pushToTheController:(NSString *)className
{
    UIViewController *vc = (UIViewController *)[[NSClassFromString(className) alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark - Getters And Setters

//注解：OC 中我们很习惯的会用懒加载，当用到的时候才去加载它，但是实际上只要一个类实现了某个方法，就会被加载进内存。
- (NSArray<NSString *> *)titleArray
{
    if (_titleArray == nil)
    {
        _titleArray = @[@"关键字",@"Runtime",@"Runloop",@"消息转发",@"Method",@"Class",@"isKindOfClass",@"Block",@"线程管理",@"gcd",@"NSError 探究",@"枚举",@"断言"];
    }
    
    return _titleArray;
}

- (NSArray<NSString *> *)controllerArray
{
    if (_controllerArray == nil)
    {
        _controllerArray = @[@"KeywordViewController",@"RunTimeViewController",
                             @"RunloopViewController",@"MessageViewController",
                             @"MethodViewController",@"ClassViewController",
                             @"IsKindClassViewController",@"BlockViewController",
                             @"ThreadManagerViewController",@"GCDTableViewController",
                             @"ErrorTableViewController",@"EnumerationTableViewController",
                             @"AssertTableViewController"];
    }
    
    return _controllerArray;
}

@end
